package main

import (
	"fmt"
	"sync"
)

//func finished()  {
//	fmt.Println("Finished finding largest")
//}
//
//func largest(nums []int)  {
//	defer finished()
//	fmt.Println("Started finding largest")
//	max:=nums[0]
//	for _,v:=range nums{
//		if v>max{
//			max=v
//		}
//		fmt.Println(v)
//	}
//	fmt.Println("Largest number in",nums,"is",max)
//}
//
//func main()  {
//	nums:=[]int{78,109,2,563,300}
//	largest(nums)
//}

//
//type person struct {
//	firstName string
//	endName string
//}
//
//func (p person) fullName() {
//	fmt.Printf("%s%s",p.firstName,p.endName)
//}
//
//func main()  {
//	p:=person{"袁","柯"}
//	defer p.fullName()
//	fmt.Println("Welcome")
//
//}

//func main()  {
//	name:="Naveen"
//	fmt.Println(string(name))
//	fmt.Println("Name List:")
//	for _,v:=range []rune(name){
//		defer fmt.Printf("%c",v)
//	}
//}

type rect struct {
	length int
	width  int
}

func (r rect) area(wg *sync.WaitGroup) {
	if r.length < 0 {
		fmt.Printf("rect %v's length should be greater than zero\n", r)
		wg.Done()
		return
	}
	if r.width < 0 {
		fmt.Printf("rect %v's width should be greater than zero\n", r)
	}
	area := r.length * r.width
	fmt.Printf("rect %v's area %d\n", r, area)
	wg.Done()
}

func main() {
	var wg sync.WaitGroup
	r1 := rect{-67, 89}
	r2 := rect{5, -67}
	r3 := rect{8, 9}
	rects := []rect{r1, r2, r3}
	for _, v := range rects {
		wg.Add(1)
		go v.area(&wg)
	}
	wg.Wait()
	fmt.Println("All executing")

}
